//
//  CXBigCollectionViewCell.m
//  Delicious
//
//  Created by dllo on 15/11/25.
//  Copyright © 2015年 doll. All rights reserved.
//

#import "CXBigCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "CXRecommendCollectionModel.h"

@interface CXBigCollectionViewCell ()

@property (nonatomic, retain) UIImageView *sanImg;
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UILabel *descrLabel;

@property (nonatomic, retain) UIView *layerView;
@property (nonatomic, retain) CAGradientLayer *gradientLayer;

@end

@implementation CXBigCollectionViewCell

///重写父类初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        //轮播图图片
        self.sanImg = [[UIImageView alloc] init];
        [self.sanImg setBackgroundColor:[UIColor whiteColor]];
        [self.contentView addSubview:self.sanImg];
        [self.sanImg setUserInteractionEnabled:YES];
        
        //轮播图标题
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.textColor = [UIColor whiteColor];
        [self.titleLabel setTextAlignment:NSTextAlignmentCenter];
        self.titleLabel.font = [UIFont boldSystemFontOfSize:19];
        [self.contentView addSubview:self.titleLabel];
        
        //标题的详细说明
        self.descrLabel = [[UILabel alloc] init];
        self.descrLabel.textColor = [UIColor whiteColor];
        [self.descrLabel setTextAlignment:NSTextAlignmentCenter];
        self.descrLabel.font = [UIFont boldSystemFontOfSize:12];
        [self.contentView addSubview:self.descrLabel];
        
        //初始化
        self.layerView = [[UIView alloc] init];
        self.gradientLayer = [CAGradientLayer layer];
        self.gradientLayer.colors = [NSArray arrayWithObjects:(id)[UIColor clearColor].CGColor,(id)[UIColor blackColor].CGColor, nil];
        self.gradientLayer.startPoint = CGPointMake(0.5, 0.5);
        self.gradientLayer.endPoint = CGPointMake(0.5, 1.0);
        
        [self.layerView.layer insertSublayer:self.gradientLayer atIndex:0];
        [self.sanImg addSubview:self.layerView];
        
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
    self.sanImg.frame =CGRectMake(0, 0, WIDTH, 264 * SCALE);
    self.titleLabel.frame =CGRectMake(0, 202 * SCALE, WIDTH, 30 * SCALE);
    self.descrLabel.frame = CGRectMake(0, 232 * SCALE, WIDTH, 18 * SCALE);
    
    //设置frame
    self.layerView.frame = CGRectMake(0, self.sanImg.frame.origin.y + self.sanImg.frame.size.height - 150 * SCALE, self.sanImg.frame.size.width, 150 * SCALE);
    self.gradientLayer.bounds = self.layerView.bounds;
    self.gradientLayer.frame = self.layerView.bounds;
}

- (void)setModel_recommend:(CXRecommendCollectionModel *)model_recommend
{
    
    if (_model_recommend != model_recommend) {
        _model_recommend = model_recommend;
    }
    [self.sanImg sd_setImageWithURL:[NSURL URLWithString:self.model_recommend.titlepic] placeholderImage:[UIImage imageNamed:@"jiazaitu"]];
    self.titleLabel.text = self.model_recommend.title;
    //NSLog(@"%@", self.titleLabel.text);
    self.descrLabel.text = self.model_recommend.descr;
}


@end
